﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using XichLoGreen.Models;

namespace XichLoGreen.Controllers
{
    public class AdminController : Controller
    {
        //
        // GET: /Admin/

        public ActionResult Index(UserModel admin)
        {
            return View();
        }
        
        [HttpPost]
        public ActionResult Login(FormCollection frmCollection)
        {
            var usrname = frmCollection.GetValue("username");
            var passwd = frmCollection.GetValue("password");
            if (usrname != null && passwd != null)
            {
                if (usrname.AttemptedValue.Equals("admin") && passwd.AttemptedValue.Equals("123"))
                {
                    var admin = new UserModel() { Name = "Admin A", Username = "admin", Type = UserType.ADMIN };
                    Session["Account"] = admin;
                }
            }

            return RedirectToAction("Index");
        }

        public ActionResult Logout()
        {
            Session["Account"] = null;
            return RedirectToAction("Index");
        }
    }
}
